new Vue({
    el:"#app",
    data:{
        items: [],
        selectItem: {},
        isLoading: true,
    },
    methods:{
        //定义一个函数，用于通过ajax方法访问后端
        getData(){
            axios.post('/model/getallapp', {
              headers: { 
                'Content-Type': 'application/json;charset=UTF-8', 
                Accept: 'application/json' 
              },
            })
            .then(res=>{
              const { status, data } = res;
              if (status == 200 && data && data.length >0) {
                this.items = data;
                //默认选中第一条
                this.selectItem = data[0];
                //只有单条数据时直接链接到子应用
                if (data.length == 1) {
                  window.location.href=data[0].path;
                }else {
                  this.isLoading = false;
                }
              }
            })
        },
        onClick(item) {
          this.selectItem = item;
        },
        onConfirm() {
          if (this.selectItem.codeName) {
            axios.post('/model/setactiveapp',this.selectItem, {
              headers: { 'Content-Type': 'application/json;charset=UTF-8', Accept: 'application/json' },
            }).then(res => {
              const { status, data } = res;
              if (status == 200 && data && data.path) {
                window.location.href = data.path;
              }
            })
          }
        }
    },
    created(){ 
      this.getData();
    }
  })